package com.hhq.sso.system.entity;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springblade.core.tool.node.INode;

/**
 * <p>
 * Description: 菜单
 * </p>
 *
 * @author : xiaodong.yang
 * @date : 2024/6/14 18:24
 */
@Data
@TableName("t_menu")
@Schema(description = "Menu对象")
public class Menu implements Serializable, INode<Menu> {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Schema(description = "主键")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 菜单父主键
     */
    @Schema(description = "父主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    /**
     * 菜单编号
     */
    @Schema(description = "菜单编号")
    private String code;

    /**
     * 菜单名称
     */
    @Schema(description = "菜单名称")
    private String name;

    /**
     * 菜单别名
     */
    @Schema(description = "菜单别名")
    private String alias;

    /**
     * 请求地址
     */
    @Schema(description = "请求地址")
    private String path;

    /**
     * 菜单资源
     */
    @Schema(description = "菜单资源")
    private String source;

    /**
     * 排序
     */
    @Schema(description = "排序")
    private Integer sort;

    /**
     * 菜单类型
     */
    @Schema(description = "菜单类型")
    private Integer category;

    /**
     * 操作按钮类型
     */
    @Schema(description = "操作按钮类型")
    private Integer action;

    /**
     * 是否打开新页面
     */
    @Schema(description = "是否打开新页面")
    private Integer isOpen;

    /**
     * 备注
     */
    @Schema(description = "备注")
    private String remark;

    /**
     * 是否已删除
     */
    @TableLogic
    @Schema(description = "是否已删除")
    private Integer isDeleted;

    /**
     * 是否有子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @TableField(exist = false)
    private Boolean hasChildren;

    /**
     * 子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @TableField(exist = false)
    private List<Menu> children;

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        Menu other = (Menu)obj;
        return this.getId().equals(other.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, parentId, code);
    }

    @Override
    public List<Menu> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }
}
